//
//  ZGLBetConfirmCell.m
//  ZeegingLottery
//
//  Created by Alfa Li on 2018/6/14.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLBetConfirmCell.h"
#import "ZGLOddsTabView.h"
#import "ZGLOddsView.h"


@interface ZGLBetConfirmCell ()

@property (nonatomic, strong)UILabel *gameNumLabel;
@property (nonatomic, strong)UILabel *teamNameLable;

@property (nonatomic, strong)ZGLOddsTabView *oddsTabView;


@end

@implementation ZGLBetConfirmCell

//重写frame设置cell间隙
- (void)setFrame:(CGRect)frame
{
    frame.size.height -= 10;
    
    [super setFrame:frame];
}

+ (instancetype)betConfirmCellWithTableView:(UITableView *)tableView
{
    static NSString *ZGLBetConfirmCellId = @"ZGLBetConfirmCellId";
    ZGLBetConfirmCell *cell = [tableView dequeueReusableCellWithIdentifier:ZGLBetConfirmCellId];
    if (!cell) {
        cell = [[ZGLBetConfirmCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ZGLBetConfirmCellId];
        
    }
    return cell;
}

+ (instancetype)betConfirmCellWithTableView:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath
{
    NSString *ZGLBetConfirmCellId = [NSString stringWithFormat:@"ZGLBetConfirmCellId%ld%ld",indexPath.section,indexPath.row];
    ZGLBetConfirmCell *cell = [tableView dequeueReusableCellWithIdentifier:ZGLBetConfirmCellId];
    if (!cell) {
        cell = [[ZGLBetConfirmCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ZGLBetConfirmCellId];
        
    }
    return cell;
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.gameNumLabel];
        [self.contentView addSubview:self.teamNameLable];

        [self.contentView addSubview:self.oddsTabView];
        
        [self setupUI];
    }
    
    return self;
}

//数据赋值
- (void)setModel:(ZGLAgainstModel *)model
{
    _model = model;
    NSString *gameNumString = [NSString stringWithFormat:@"%@ %@",model.matchkeycn,model.leaguenameabbr];
    NSString *teamNameString = [NSString stringWithFormat:@"(主)%@VS%@",model.home.teamname,model.away.teamname];
    self.gameNumLabel.text = gameNumString;
    self.teamNameLable.text = teamNameString;
    self.oddsTabView.selectStateArray = model.stateArray;
    self.oddsTabView.Againstmodel = model;
    self.oddsTabView.hadModel = model.had;
    self.oddsTabView.hhadModel = model.hhad;
    
}


#pragma mark - getter

- (void)setupUI
{
    
    [_gameNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(20);
        
    }];
    
    [_teamNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-20);
        make.centerY.equalTo(_gameNumLabel);
        make.left.equalTo(_gameNumLabel.mas_right).offset(10);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = BorderColor;
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_teamNameLable.mas_bottom).offset(10);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.equalTo(@(kBorderWidth));
        
    }];
    
    [_oddsTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_gameNumLabel.mas_left);
        make.top.equalTo(line.mas_bottom).offset(10);
        make.right.equalTo(_teamNameLable.mas_right);
        make.height.equalTo(@(sBtnH));
    }];

    
    
}


- (ZGLOddsTabView *)oddsTabView
{
    if (!_oddsTabView) {
        CGFloat btnW = UI_SCREEN_WIDTH;
        _oddsTabView = [[ZGLOddsTabView alloc]initWithFrame:CGRectMake(0, 0, btnW, sBtnH)];
        WS(weakself)
        
        _oddsTabView.matchArrBlock = ^(NSInteger Num) {
            //返回场数
            if (weakSelf.countBlock) {
                weakSelf.countBlock(Num);
            }
        };

    }
    return _oddsTabView;
}


- (UILabel *)gameNumLabel
{
    if (!_gameNumLabel) {
        _gameNumLabel = [[UILabel alloc]init];
        _gameNumLabel.font = [UIFont systemFontOfSize:14];
        _gameNumLabel.textColor = detailTextColor;
        _gameNumLabel.textAlignment = 0;
        _gameNumLabel.text = @"周四 001 英超";
    }
    return _gameNumLabel;
    
}

- (UILabel *)teamNameLable
{
    if (!_teamNameLable) {
        _teamNameLable = [[UILabel alloc]init];
        _teamNameLable.font = [UIFont systemFontOfSize:14];
        _teamNameLable.textColor = mainTextColor;
        _teamNameLable.textAlignment = 2;
        _teamNameLable.text = @"(主)巴塞罗那VS皇家马德里";
        
    }
    return _teamNameLable;
}


@end
